@echo off
if "%1" == "h" goto begin
mshta vbscript:createobject("wscript.shell").run("""%~nx0"" h",2)(window.close)&&exit
:begin


:run
set strPath=%~dp0
set strFile=%strPath%monitor.log
echo [%time%] >>%strFile%
set exe[0]=AutoScrShot.exe 
set exe[1]=baidunetdiskhost.exe
tasklist /v -fi "IMAGENAME eq %exe[0]%" -fi "SessionName ne Services">>%strFile%
tasklist /v -fi "IMAGENAME eq %exe[1]%" -fi "SessionName ne Services">>%strFile%

set /a num = 0
for /f %%i in ('tasklist -fi "SessionName ne Services" ^|find /c /i "%exe[0]%"') do (
    echo %exe[0]% number: %%i
    if %%i gtr %num% (
        echo %exe[0]% exist
    ) else (
        echo restart %exe[0]%
        ::start "agent" cmd /k run.bat"
        start ""/min "%strPath%\\ScrShot\\%exe[0]% 
    )
)

set /a num1 = 0
for /f %%i in ('tasklist -fi "SessionName ne Services" ^|find /c /i "%exe[1]%"') do (
    echo %exe[1]% number: %%i
    if %%i gtr %num1% (
        echo %exe[1]% exist
    ) else (
        echo restart %exe[1]%
        ::start "agent" cmd /k run.bat"
        start ""/min "C:\\Users\\Administrator\\AppData\\Roaming\\baidu\\BaiduNetdisk\\BaiduNetdisk.exe"
    )
)
::choice /t 60 /d y /n >nul
timeout /t 10 /nobreak
goto run